﻿<UserControl x:Class="FacebookClient.NotificationsControl" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:FacebookClient="clr-namespace:FacebookClient"
    xmlns:ClientManager="clr-namespace:ClientManager" 
    xmlns:ClientManagerControls="clr-namespace:ClientManager.Controls"
    xmlns:Facebook="clr-namespace:Contigo;assembly=Contigo"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    MinWidth="250" MaxWidth="350"
    x:Name="ThisControl">
  
  <UserControl.Resources>
    <!-- Can't do this directly in the Setter because of a bug in WPF. -->
    <TextBlock x:Key="DescriptionToolTip" Text="{Binding DescriptionText}" TextWrapping="Wrap" MaxWidth="350" />
    
    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
  </UserControl.Resources>
  
  <Border Background="{DynamicResource ContentChromeBackground}" Padding="1" BorderThickness="1" BorderBrush="LightGray"
          Visibility="{Binding ElementName=ThisControl, Path=IsDisplayed, Converter={StaticResource BooleanToVisibilityConverter}}">
    <Grid>
      <StackPanel>
        <DockPanel>
          <Button DockPanel.Dock="Right" Margin="5" Content="0" Style="{StaticResource SimpleButtonStyle}" FontFamily="Webdings" Foreground="White" Command="{x:Static FacebookClient:NotificationsControl.CloseCommand}" ToolTip="Hide notifications" />
          <TextBlock Text="Notifications" Foreground="White" FontFamily="{DynamicResource SansSerifFont}" FontSize="{DynamicResource LargeFontSize1}" FontWeight="Bold" Margin="5" />
        </DockPanel>
        <StackPanel x:Name="ItemsPanel">
          <ItemsControl x:Name="NotificationList"
              Background="{DynamicResource PopupListControlBackgroundBrush}"
              Padding="5" 
              ItemsSource="{Binding Source={x:Static ClientManager:ServiceProvider.ViewManager}, Path=Notifications}">
            <ItemsControl.ItemTemplate>
              <DataTemplate DataType="{x:Type Facebook:Notification}">
                <DockPanel Margin="0,0,0,5">
                  <Rectangle DockPanel.Dock="Top" 
                      Height="1"
                      SnapsToDevicePixels="True" 
                      Width="240" 
                      VerticalAlignment="Top" 
                      HorizontalAlignment="Center" 
                      Fill="{DynamicResource NewsFeedItemDividerBrush}" />
                  <Button DockPanel.Dock="Right" 
                      Content="r"
                      Foreground="{DynamicResource PopupListControlDeleteItemBrush}" 
                      FontFamily="Webdings" 
                      Style="{StaticResource SimpleButtonStyle}" 
                      VerticalAlignment="Top" 
                      Command="{Binding Source={x:Static ClientManager:ServiceProvider.ViewManager}, Path=ActionCommands.MarkAsReadCommand}" 
                      CommandParameter="{Binding}" 
                      Margin="10,0,2,0"
                      ToolTip="Mark as read"
                      FontWeight="Bold" />
                  <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal">
                    <ClientManagerControls:FacebookImageControl DockPanel.Dock="Left" FacebookImage="{Binding Path=Icon}" FacebookImageDimensions="Small">
                      <ClientManagerControls:FacebookImageControl.Template>
                        <ControlTemplate TargetType="{x:Type ClientManagerControls:FacebookImageControl}">
                          <Image Width="16" Height="16" Margin="2,5,7,0" HorizontalAlignment="Left" VerticalAlignment="Top" Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ImageSource}" />
                        </ControlTemplate>
                      </ClientManagerControls:FacebookImageControl.Template>
                    </ClientManagerControls:FacebookImageControl>
                    <TextBlock VerticalAlignment="Center" TextWrapping="Wrap" Text="{Binding Updated, Converter={StaticResource DateTimeConverter}}">
                      <TextBlock.Style>
                        <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource CreatedTextBlockStyle}">
                          <Setter Property="Visibility" Value="Visible"/>
                          <Style.Triggers>
                            <DataTrigger Binding="{Binding Updated}" Value="{x:Static sys:DateTime.MinValue}">
                              <Setter Property="Visibility" Value="Collapsed"/>
                            </DataTrigger>
                          </Style.Triggers>
                        </Style>
                      </TextBlock.Style>
                    </TextBlock>
                  </StackPanel>
                  <TextBlock TextWrapping="Wrap">
                    <TextBlock.Style>
                      <Style TargetType="{x:Type TextBlock}">
                        <!-- We want the tooltip to not be present if there's no content. -->
                        <Setter Property="ToolTip" Value="{StaticResource DescriptionToolTip}"/>
                        <Style.Triggers>
                          <DataTrigger Binding="{Binding DescriptionText}" Value="">
                            <Setter Property="ToolTip" Value="{x:Null}" />
                          </DataTrigger>
                        </Style.Triggers>
                      </Style> 
                    </TextBlock.Style>
                    <FacebookClient:HyperlinkTextContent Text="{Binding Title}" FontFamily="{DynamicResource SansSerifFont}" FontSize="{DynamicResource MiddleFontSize}" RequestNavigate="_OnNotificationRequestNavigate" Foreground="{DynamicResource NotificationMessageTextForeground}"/>
                  </TextBlock>
                </DockPanel>
              </DataTemplate>
            </ItemsControl.ItemTemplate>
          </ItemsControl>
          <Button Content="Mark all as read"
              Margin="5"
              FontFamily="{DynamicResource SansSerifFont}"
              FontSize="{DynamicResource MiddleFontSize}"
              Foreground="White"
              HorizontalAlignment="Left" 
              Style="{StaticResource SimpleButtonStyle}" 
              Command="{Binding Source={x:Static ClientManager:ServiceProvider.ViewManager}, Path=ActionCommands.MarkAllAsReadCommand}" 
              CommandParameter="{Binding Source={x:Static ClientManager:ServiceProvider.ViewManager}, Path=Notifications}"/>
        </StackPanel>
      </StackPanel>
    </Grid>
  </Border>
</UserControl>
